<?php

#--------------------------------------------------
# ALL INCLUDES + STANDARD-VALUES
#--------------------------------------------------
include_once ("include/config.inc");
include_once ("include/template.inc");
include_once ("include/class.db.php5");
include_once ("include/class.tools.php5");
include_once ("include/class.time.php5");
$svo = new db("svoptik");
$tools = new tool();
$time = new TimeUtil();

include_once ("stats_inc.php5");
include_once ("include/global_fix_extern.inc");

if (empty ($team_id))
	$team_id = 1;

if (!isset ($cat))
	$cat = "News";
switch ($cat) {
	case News :
		$url_news = "";
		$url_team = "team.php5?team_id=" . $team_id . "&cat=Team";
		$tpl = "team.tpl";
		break;
	case Team :
		$url_news = "team.php5?team_id=" . $team_id . "&cat=News";
		$url_team = "";
		$tpl = "news.tpl";
		break;
}
//$month = date("m");
//if ($month < 7) {
//	$saison = (date("Y") - 1) . "-" . date("Y");
//} else {
//	$saison = date("Y") . "-" . (date("Y") + 1);
//}
//$sql = "select t.*, s.*, g.*, l.*, gl.* from " . $table['Team'] . " as t, " . $table['G_Team'] . " as g, " . $table['Saison'] . " as s, " . $table['Liga'] . " as l, " . $table['G_Liga'] . " as gl where t.stats_team_id=" . $team_id . " && l.stats_leagues_global_id=gl.stats_leagues_global_id && t.stats_team_global_id=g.stats_team_global_id && l.stats_leagues_id=t.stats_team_league && s.stats_season_id=" . $current_season_id . ";";
//$team_data = $svo->readRecordset($sql);
//#echo "select t.*, s.*, g.*, l.* from ".$table['Team']." as t, ".$table['G_Team']." as g, ".$table['Saison']." as s, ".$table['Liga']." as l where t.stats_team_id=".$team_id." && t.stats_team_global_id=g.stats_team_global_id && l.stats_leagues_id=t.stats_team_league && t.stats_team_season=".$current_season_id.";";
//$team = $team_data['stats_team_global_class'] . " " . $team_data['stats_team_global_index'];

#--------------------------------------------------
# CREATE TEMPLATE
#--------------------------------------------------
$t = new Template("templates", "keep");
if ($cat == "Team") {
	$t->set_file(array (
		"page" => "svoptik.tpl",
		"ticker" => "ticker.tpl",
		"navi" => "navi.tpl",
		"team" => "team.tpl"
	));
} else {
	$t->set_file(array (
		"page" => "svoptik.tpl",
		"ticker" => "ticker.tpl",
		"navi" => "navi.tpl",
		"news" => "news.tpl"
	));
}

$t->set_var(array (
	"FORWARD" => ""
));
#--------------------------------------------------
# CREATE ALL-TIME SAME THINGS
#--------------------------------------------------
include_once ("include/sameThings.php5");

#--------------------------------------------------
# CREATE NAVIGATION LEFT
#--------------------------------------------------
if (!isset($team_id)){
	$team_id = 1;
}

$actTeam = $teamDao->findById($team_id);
$links = "";
$m = 1;
$url[0] = array (
	"URL" => "",
		"URL-TEXT" => $actTeam->name, //$team_data['stats_team_global_class'] . " " . $team_data['stats_team_global_index'],
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => $url_news,
	"URL-TEXT" => "-&nbsp;News",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => $url_team,
	"URL-TEXT" => "-&nbsp;Team",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "team_tab.php5?team_id=" . $team_id,
	"URL-TEXT" => "-&nbsp;Tabelle",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "team_schedule.php5?team_id=" . $team_id . "&complete=0",
	"URL-TEXT" => "-&nbsp;Spielplan",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "team_stats.php5?team_id=" . $team_id,
	"URL-TEXT" => "-&nbsp;Statistiken",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "",
	"URL-TEXT" => "SPACER",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
/*$url[$m++] = array("URL"   => "",
                "URL-TEXT" => "Archiv",
                "ONCLICK"  => "alert('im Aufbau')",
                "TARGET"   => "_self");*/

for ($i = 0; $i < count($url); $i++) {
	if ($url[$i]['URL-TEXT'] != "SPACER") {
		if (!empty ($url[$i]['URL']))
			$slink = "<a href=\"" . $url[$i]['URL'] . "\" class=\"sitenav\" target=\"" . $url[$i]['TARGET'] . "\" onClick=\"" . $url[$i]['ONCLICK'] . "\">" . $tools->html_replace($url[$i]['URL-TEXT']) . "</a>";
		else
			$slink = "<b>" . $tools->html_replace($url[$i]['URL-TEXT']) . "</b>";
	} else
		$slink = "&nbsp;";
	$links .= "
	        <tr height=\"15\">
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
				<td valign=\"top\" class=\"sitenav\">" . $slink . "</td>
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			</tr>
	       ";
}
$t->set_var(array (
	"LINKS" => $links,
	"BANNER" => $banner
));
$right_nav = $t->parse("", "navi", true);
#--------------------------------------------------

#--------------------------------------------------
# CREATE ALL-TIME SAME THINGS
#--------------------------------------------------
include_once ("include/sameThings.php5");

#--------------------------------------------------

#--------------------------------------------------
# CREATE CONTENT "TEAMSITE"
#--------------------------------------------------
if ($cat == "Team") {
	if (is_file("images/teams/" . $actTeam->foto)) {
		$link_foto = "<img src=\"images/teams/" . $actTeam->foto . "\" width=\"550\" border=\"0\" hspace=\"5\" vspace=\"5\" alt=\"\" title=\"".$actTeam->name."\">";
	} else {
		$link_foto = "Teamfoto in Arbeit";
	}
	
	$t->set_var(array (
		"FOTO" => $link_foto,
		"LIGA" => $actTeam->liga,
		"SAISON" => $actTeam->saison,
		"KLASSE" => $actTeam->klasse
	));
	$content .= $t->parse("", "team", true);
}
#--------------------------------------------------
# CREATE CONTENT "NEWS"
#--------------------------------------------------
if ($cat == "News") {
	include_once('dataAccess/classes/Report.php5');
	include_once('dataAccess/dao/ReportDAO.php5');
	
	$reportDao = new ReportDAO();
	$content = "";
	$ausgabe = "";
	
	$reports = $reportDao->findNewsForTeamSeite($actTeam->id);
	$i = 0;
	$j = 0;
	if ($reports){
		foreach ($reports as $report){
			$diff = strlen($report->text) - strlen(strip_tags($report->text));
			$length = 700 + $diff;
			if (strlen(strip_tags($report->text)) > $length){
				$link = "... <a href=\"show_report.php5?id=" . $report->id . "\" class=\"news\">mehr</a>";
			}
			else {
				$link = "&nbsp";
			}
		
			$headline = "<a href=\"show_report.php5?id=" . $report->id . "\" class=\"news\"><font size=\"2\">" . $tools->html_replace($report->headline) . "</font></a>";
		
			$image = "";
			// bild setzen
			$imgDir = "images/reports/" . $report->authorId . "/";
			if (strlen($report->img) > 0) {
				$image = sprintf("<a href=\"%s\" target=\"_blank\"><img src=\"%s\" class=\"reportImg\" alt=\"%s\" title=\"%s\" align=\"left\" border=\"0\"/></a>", $imgDir .
				$tools->html_replace($report->img), $imgDir .
				$tools->html_replace($report->imgTh), $tools->html_replace($report->imgSubTitle), $tools->html_replace($report->imgSubTitle));
				$text = $image . " " . substr($report->text, 0, $length);
			} else {
				$text = substr($report->text, 0, $length);
			}
			$author = "(<a href=\"mailto:" . $report->authorMail . "\" class=\"news\">" . $report->authorName . "</a>)";
		
			# Geburtstagsgruss
			if ($bdayTrue && $i == 0){
				$ausgabe = "<tr><td valign='top' align='center' class='bday'>" . $gruss . "</td></tr>";
			} else {
				$ausgabe = "";
			}
		
			$t->set_var(array (
				"LINK" => $link,
				"KATEGORIE" => $tools->html_replace($report->cat
			), "HEADLINE" => "<font class=\"newsHeadline\">" . $tools->html_replace($report->headline) . "</font>", "DATUM" => $time->out($report->date, 'd'), "TEXT" => $text, "AUTHOR" => $author, "BDAY" => $ausgabe, "ANCHOR" => $report->id));
		
			$content .= $t->parse("", "news", true);
			$i++;
		}
	}
}
#--------------------------------------------------

#--------------------------------------------------
# PARSE & OUTPUT
#--------------------------------------------------
$t->set_var(array (
	"sitenav" => "TEAMS -> " . $tools->html_replace(strtoupper("Red Eagles Rathenow - " . $actTeam->name . " " . $actTeam->suffix
)) . " (SAISON " . $actTeam->saison . "/".($actTeam->saison + 1).")", //.$team_data['stats_season_name'].")",
"ticker" => $ticker, "content" => $content . "<br>", "navi" => $right_nav,
	"SYNCHRONIZE" => " "));

$t->parse("ALL", "page", true);
$t->p("ALL");
?>
